package toy.keli.picmap.service;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

import toy.keli.picmap.model.db;

//https://www.jianshu.com/p/ea8bc4aaf057
public class KpmContentProvider extends ContentProvider {
    public static final String AUTOHORITY = "toy.keli.picmap";
    private Context mContext;
    // UriMatcher类使用:在ContentProvider 中注册URI
    private static final UriMatcher mMatcher;
    static{
        mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
        // 初始化
        mMatcher.addURI(AUTOHORITY,"test", 1);
    }
    static enum tables{
        PIC,
        PATH
    }
    public KpmContentProvider() {
    }
    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {
        String table = "pic"; //mMatcher.match(uri);
        return db.cursor().query(table,projection,selection,selectionArgs,null,null,sortOrder,null);
    }
    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // Implement this to handle requests to delete one or more rows.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public String getType(Uri uri) {
        // TODO: Implement this to handle requests for the MIME type of the data
        // at the given URI.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        // TODO: Implement this to handle requests to insert a new row.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public boolean onCreate() {
        mContext = getContext();
        // 运行在主线程，故不能做耗时操作,此处仅作展示
        db.init(getContext());
        // TODO: Implement this to initialize your content provider on startup.
        return false;
    }



    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
        // TODO: Implement this to handle requests to update one or more rows.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}